var hdsavesum = (function (){
	
	this.init = function (){
        this.updateSaveSum();
        $("#btnSaveSum").click( function(){
        	var tempSum = "", str, i, temp;
			str = $("#txtSaveSum").val().split(',');
			for (i = 0; i < str.length; i += 1) {
				tempSum += str[i];
			}
        	var newData = {
        		SavingID:parseInt($("#selSaveSumSavingList option:selected").val()),
        		AccountID:parseInt($("#selSaveSumAccountList option:selected").val()),
        		Sum:parseFloat(tempSum)
        	};
        	data.saveSum(newData);
        	$("#txtSaveSum").val("");
            hdcurrentstate.show();
        });
	};
    this.updateSaveSum = function(){
        data.getAccountList( function (results) {
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).AccountID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selSaveSumAccountList").html(str).selectmenu('refresh');
            }
        });
        data.getSavingsList( function( results ){
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).SavingID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selSaveSumSavingList").html(str).selectmenu('refresh');
            }
        });
    };
	this.init();
	return this;
}(hdsavesum || {}));
